package com.levi.service;

import com.levi.domain.User;
import com.levi.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

/**
 * @author shentong
 * @since 2022/7/17 22:46
 */
@Service
public class MongoService {

    @Autowired
    private UserRepository userRepository;


    @Transactional
    public String testTransaction() {
        Optional<User> optionalUser = userRepository.findById("62d40a6d7444e8460ae3f34f");
        if (optionalUser.isPresent()) {
            User user = optionalUser.get();
            user.setName("suolong");
            userRepository.save(user);
        }
        int i = 1 / 0;
        return "seccess";
    }
}
